<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts';
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize';
import axios from 'axios';
const animationDuration = 3000

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '400px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      axios.get('/manage/browseRecords/getMembersSevenDaysActive').then(res => {
        const result = res.data.data
        const data = Object.keys(result)
        let val = []
        for (const k in result) {
          val.push(result[k])
        }
        this.chart = echarts.init(this.$el, 'macarons')
        this.chart.setOption({
          title: {
            text: '最近七天活跃人数'
          },
          xAxis: {
            type: 'category',
            data: data
          },
          yAxis: {
            type: 'value'
          },
          series: [
            {
              data: val,
              type: 'line'
            }
          ]
        })
      })
    }
  }
}
</script>
